package com.rpc;

/**
 * @Author PABLO
 * @Date 2022/6/25 11:42
 * @Desc
 */
public class Singleton {

    private static final Singleton OBJECT = new Singleton();

    private Singleton() {
    }

    public Singleton getObject() {
        return OBJECT;
    }
}

class Singleton2 {
    private static volatile Singleton2 OBJECT = null;

    private Singleton2() {
    }

    public static Singleton2 getObject() {
        if (OBJECT == null) {
            synchronized (Singleton2.class) {
                if (OBJECT == null) {
                    return OBJECT = new Singleton2();
                }
            }
        }
        return OBJECT;
    }
}


class ThreadSecuritySingleton {

    public ThreadSecuritySingleton getObject() {
        return InnerClass.OBJECT;
    }

    static class InnerClass {
        private static final ThreadSecuritySingleton OBJECT = new ThreadSecuritySingleton();
    }


    public static void main(String[] args) {

        Runnable runnable = () -> {
            Singleton2 myObject = Singleton2.getObject();
            System.out.println(Thread.currentThread().getName() + "****" + myObject.hashCode());
        };

        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(runnable);
            Thread thread1 = new Thread(runnable);
            thread.start();
            thread1.start();

        }

    }
}

class AAA {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = new String("abc");
        System.out.println(str1.equals(str2));
    }
}